#!/usr/bin/env python
# -*- coding: UTF-8 -*-
TEMPLATE = "index_template.html"
TMP_VARIABLES = {"LO": "", "LA": ""}

# enable debugging
import cgitb, urllib, json

cgitb.enable()
from string import Template

class GoogleLatitude:
    """Menangen location simple class"""

    @staticmethod
    def GetLocation():
        f = urllib.urlopen("http://www.google.ru/latitude/apps/badge/api?user=-1772031887248867614&type=json")
        JSON = f.read()
        JSON_data = json.loads(JSON)
        coordinates = JSON_data["features"][0]['geometry']['coordinates']
        return coordinates

try:
    location = GoogleLatitude.GetLocation()
    TMP_VARIABLES["LA"] = location[0]
    TMP_VARIABLES["LO"] = location[1]
except:
    pass

template_HTML = ""

file = open(TEMPLATE, "r")
for line in file:
    template_HTML += line
file.close()

template = Template(template_HTML)

print "Content-Type: text/html;charset=utf-8"
print

print template.substitute(TMP_VARIABLES)
